package com.gzsxy.esjy.service.order.controller.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gzsxy.esjy.service.base.dto.request.ApiOrderRequest;
import com.gzsxy.esjy.service.base.dto.response.DefaultResponse;
import com.gzsxy.esjy.service.base.dto.response.OrderRsp;
import com.gzsxy.esjy.service.base.util.Page;
import com.gzsxy.esjy.service.order.entity.vo.OrderQueryVo;
import com.gzsxy.esjy.service.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 前台订单管理
 * @date 2022/2/18 16:27
 */
@CrossOrigin  //解决跨域
@RefreshScope    //动态刷新配置文件-外部配置文件
@RestController
@RequestMapping("/api/order")
@Api("订单管理")
public class ApiOrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/add")
    @ApiOperation("添加订单")
    public DefaultResponse addOrder(@RequestBody ApiOrderRequest apiOrderRequest){
        List<String> list = orderService.addOrder(apiOrderRequest);
        return DefaultResponse.ok(list);
    }


    @GetMapping("/user")
    @ApiOperation("根据前台用户id获取订单列表")
    public DefaultResponse getOrderByUserId(Page<?> page, OrderQueryVo orderQueryVo){
        IPage<OrderRsp> list = orderService.getOrderByUserId(page,orderQueryVo);
        return DefaultResponse.ok(list);
    }


    @PutMapping("/{orderId}")
    @ApiOperation("改变订单状态")
    public DefaultResponse eidtStatus(@PathVariable String orderId,@RequestBody ApiOrderRequest apiOrderRequest){
        orderService.eidtStatus(orderId,apiOrderRequest.getStatus());
        return DefaultResponse.ok();
    }



}
